<?php
header("Content-type:text/html;charset=utf-8");
$mysql = mysqli_connect("localhost","root","root","test","3306");
if(!$mysql){exit("未连接到数据库");}
if($_SERVER["REQUEST_METHOD"] == "POST"){
  $username = $_POST['username'];
  $password = $_POST['password'];
  $twopassword = $_POST['twopassword'];
  $name = $_POST['name'];
  // $email = $_POST['email'];
  $time = time();

  if($username == ""){echo "<script>alert('用户名是必填的!');history.go(-1)</script>";}
  if($username == "admin"){echo "<scirpt>alert('用户名非法!');history.go(-1)</script>";}
  if($password == ""){echo "<script>alert('密码是必填的!');history.go(-1)</script>";}
  if($password != $twopassword){echo "<script>alert('两次密码不一致!');history.go(-1);</script>";}
  // if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){echo "<script>alert('请填写正确的邮箱格式!');history.go(-1)</script>";}

  // $email = str_replace("@qq.com","",$email);
  // define("EMAIL","@qq.com");
  // $email = $email.EMAIL;

  $insert = "INSERT INTO user (username,password,name,date) VALUES ($username,$password,$name,$time)";
  if (mysqli_query($mysql, $insert)) {
    echo "<script>alert('添加成功!');window.location.href=http://liu.com/yuan/index/index.php;</script>";
  } else {
      echo "Error: " . $insert . "<br>" . mysqli_error($mysql);
  }
  mysqli_close($mysql);
}else{

}
